package com.study.sbsummary.config.kafka;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
@ConfigurationProperties(prefix = "kafka")
@Data
public class Topics {
    Map<String, Topic> topics = new HashMap<>();

    @Data
    public static class Topic {
        private String name;
        private int partition = -1;
        private String group;
        private int consumerCnt = 2;
        private long duration = 1000;
        private String offsetReset = "earliest";
        private boolean autoCommit = false;

        public String getGroup() {
            if (group == null && name != null) {
                group = name + "-group";
            }
            return group;
        }
    }

    public int size() {
        if (topics == null) {
            return 0;
        }
        return topics.size();
    }

    public Topic getTopic(String topic) {
        return topics.get(topic);
    }
}
